home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / program / gncdev24.lha / E / DemoGenCodeE / DemoGenCodeE.e < prev    next >
Text File  |  1995-09-12  |  6KB  |  181 lines

  1. OPT OSVERSION = 37
  2. OPT PREPROCESS
  3.  
  4.  
  5. ->/////////////////////////////////////////////////////////////////////////////
  6. ->//////////////////////////////////////////////////////////// MODULE ... /////
  7. ->/////////////////////////////////////////////////////////////////////////////
  8. MODULE 'locale'
  9. MODULE 'muimaster' , 'libraries/mui'
  10. MODULE 'utility/tagitem' , 'utility/hooks'
  11. MODULE 'tools/boopsi' , 'tools/installhook'
  12. MODULE 'icon'
  13.  
  14. MODULE '*GUI'
  15.  
  16.  
  17. ->/////////////////////////////////////////////////////////////////////////////
  18. ->///////////////////////////////////////////////////////// DEF ... : ... /////
  19. ->/////////////////////////////////////////////////////////////////////////////
  20. DEF dgce    :    PTR TO app_obj            -> look at GUI.em for "app_obj" object
  21. DEF string_var    :    PTR TO CHAR            -> used by a notification (see GUI.em, lines 49 and 155)
  22.  
  23.  
  24. ->/////////////////////////////////////////////////////////////////////////////
  25. ->///////////////////////////////////////////////////////////// PROC main /////
  26. ->/////////////////////////////////////////////////////////////////////////////
  27. PROC main() HANDLE
  28.  
  29.     DEF running = TRUE , result_domethod , signal
  30.     DEF arexx : app_arexx , display : app_display
  31.     DEF change_text_hook : hook , arexx_commands : PTR TO mui_command
  32.     DEF icon = NIL
  33.  
  34.         -> needed libraries and icon init
  35.     IF ( muimasterbase := OpenLibrary( 'muimaster.library' , MUIMASTER_VMIN ) ) = NIL THEN Throw( "LIB" , "muim" )
  36.     IF ( iconbase := OpenLibrary( 'icon.library' , 0 ) ) THEN icon := GetDiskObject( 'PROGDIR:DemoGenCodeE' ) ELSE Throw( "LIB" , "icon" )
  37.  
  38.         -> exported variables init
  39.     string_var := 'String variable put !'
  40.  
  41.         -> MUI GUI init
  42.             -> in GUI.em line 22, you can see the declaration of "app_display" object
  43.             -> each field of this object correspond to a hook function declared in MUIBuilder
  44.             -> in the present case, there is only the "button_pressed" hook function (see GUI.em line 167)
  45.     installhook( display.button_pressed , {button_pressed} )
  46.  
  47.         -> ARexx init
  48.             -> for ARexx init you must fill an "app_arexx" object defined in GUI.em line 17
  49.             -> this object gets 2 fields : one for the commands and one for the arexx error hook function
  50.     installhook( change_text_hook , {change_text} )
  51.     arexx.commands := NEW arexx_commands[ 2 ]
  52.     arexx.commands[].mc_name := 'change_text'
  53.     arexx.commands[].mc_template := ''
  54.     arexx.commands[].mc_parameters := 0
  55.     arexx.commands[].mc_hook := change_text_hook
  56.     installhook( arexx.error , {arexx_error} )
  57.  
  58.         -> MUI application creation
  59.             -> for this you call the create method (see GUI.em line 57) on the "app_obj" object
  60.             -> to this method, you must give the "app_display" object
  61.             -> and if you want (not obliged), you can give an icon, the "app_arexx" object and a menu object (obsolete)
  62.     NEW dgce
  63.     IF dgce.create( display , icon , arexx ) = NIL THEN Throw( "MUI" , Mui_Error() )
  64.     dgce.init_notifications( display )
  65.  
  66.         -> Main loop
  67.     WHILE running
  68.  
  69.         result_domethod := domethod( dgce.app , [ MUIM_Application_Input , {signal} ] )
  70.         SELECT result_domethod
  71.  
  72.             CASE ID_BUTTON_PRESSED    -> see GUI.em line 42 for the definition of this ID
  73.  
  74.                 set( dgce.tx_result , MUIA_Text_Contents , 'Modifed by ID returned !' )
  75.  
  76.             CASE MUIV_Application_ReturnID_Quit
  77.  
  78.                 running := FALSE
  79.  
  80.         ENDSELECT
  81.  
  82.         IF ( signal AND running ) THEN Wait( signal )
  83.  
  84.     ENDWHILE
  85.  
  86. EXCEPT DO
  87.  
  88.     SELECT exception
  89.  
  90.         CASE "LIB"
  91.  
  92.             SELECT exceptioninfo
  93.  
  94.                 CASE "muim"
  95.  
  96.                     error_simple( 'Can''t open muimaster.library !' )
  97.  
  98.                 CASE "icon"
  99.  
  100.                     error_simple( 'Can''t open icon.library !' )
  101.  
  102.             ENDSELECT
  103.  
  104.         CASE "MEM"
  105.  
  106.             error( 'Not enough memory !' )
  107.  
  108.         CASE "MUI"
  109.  
  110.             SELECT exceptioninfo
  111.  
  112.                 CASE MUIE_OutOfMemory
  113.  
  114.                     error_simple( 'Not enough memory !' )
  115.  
  116.                 CASE MUIE_OutOfGfxMemory
  117.  
  118.                     error_simple( 'Not enough chip memory !' )
  119.  
  120.                 CASE MUIE_MissingLibrary
  121.  
  122.                     error_simple( 'Can''t open a needed library !' )
  123.  
  124.                 CASE MUIE_NoARexx
  125.  
  126.                     error_simple( 'Can''t create arexx port !' )
  127.  
  128.                 DEFAULT
  129.  
  130.                     error_simple( 'Internal problem !' )
  131.  
  132.             ENDSELECT
  133.  
  134.     ENDSELECT
  135.  
  136.     IF dgce            THEN dgce.dispose()
  137.     IF icon            THEN FreeDiskObject( icon )
  138.     IF iconbase        THEN CloseLibrary( iconbase )
  139.     IF muimasterbase    THEN CloseLibrary( muimasterbase )
  140.  
  141. ENDPROC
  142.  
  143.  
  144. ->/////////////////////////////////////////////////////////////////////////////
  145. ->/////////////////// Prints an error message with an intuition requester /////
  146. ->/////////////////////////////////////////////////////////////////////////////
  147. PROC error_simple( message : PTR TO CHAR ) IS EasyRequestArgs(    NIL , [ 20 , 0 ,
  148.                                     'DemoGenCodeE error !' ,
  149.                                     message ,
  150.                                     '_OK' ] , NIL , NIL )
  151.  
  152.  
  153. ->/////////////////////////////////////////////////////////////////////////////
  154. ->///////////////////////// Prints an error message with an MUI requester /////
  155. ->/////////////////////////////////////////////////////////////////////////////
  156. PROC error( message : PTR TO CHAR ) IS Mui_RequestA(    dgce.app ,
  157.                             dgce.wi_the_window ,
  158.                             NIL ,
  159.                             'DemoGenCodeE error !' ,
  160.                             '*_OK' ,
  161.                             message ,
  162.                             NIL )
  163.  
  164.  
  165. ->/////////////////////////////////////////////////////////////////////////////
  166. ->///////// Hook function called each time bt_call_hook button is pressed /////
  167. ->/////////////////////////////////////////////////////////////////////////////
  168. PROC button_pressed( hook , obj , msg ) IS set( dgce.tx_result , MUIA_Text_Contents , 'Modified by called hook function !' )
  169.  
  170.  
  171. ->/////////////////////////////////////////////////////////////////////////////
  172. ->///////////////////// Hook function called by ARexx command change_text /////
  173. ->/////////////////////////////////////////////////////////////////////////////
  174. PROC change_text( hook , obj , msg ) IS set( dgce.tx_result , MUIA_Text_Contents , 'Modifed by ARexx command change_text !' )
  175.  
  176.  
  177. ->/////////////////////////////////////////////////////////////////////////////
  178. ->//////////////////////// Hook function called by ARexx in case of error /////
  179. ->/////////////////////////////////////////////////////////////////////////////
  180. PROC arexx_error( hook , obj , msg ) IS error_simple( 'Unknown ARexx command recieved !' )
  181.